#include <stdio.h>
#include <stdlib.h>
struct shu//定义一个节点
{
    int data;
    struct shu* next;
};
struct shu * HEAD()//申请头节点
{
    struct shu*head = (struct shu*)malloc(sizeof(struct shu));
    head -> data = 0;
    head -> next = NULL;
    return head;
}
int main()
{
    int n;
    scanf("%d",&n);
    int arr[n];
    for(int i = 0;i < n;i++)//循环输入数组
    {
        scanf("%d",&arr[i]);
    }
    struct shu*head =HEAD();//申请头节点
    struct shu* p = head;//重新定义一个指针用来遍历链表
    for(int i = 0;i < n;i++)//遍历链表
    {
    struct shu* new = (struct shu*)malloc(sizeof(struct shu));
    new -> data = arr[i];
    new -> next = NULL;
    p -> next = new;
    p = p -> next;
    }
    struct shu* first = head -> next;//定义一个指针指向第一个节点
    struct shu* second = first -> next;//定义一个指针指向第二个节点
    int temp = first -> data;//交换第一个和第二个节点的数据
    first -> data = second -> data;
    second -> data = temp;
    struct shu* first1 = head -> next;//重新定义一个指针指向第一个节点
    struct shu* second2 = first1 -> next;//重新定义一个指针指向第二个节点
    while(second2 -> next != NULL)//循环遍历找链表最后两个节点
    {
        second2 = second2 -> next;
        first1 = first1 -> next;
    }
    int temp1 = first1 -> data;//交换最后节点
    first1 -> data = second2 -> data;
    second2 -> data = temp1;
    p = head -> next;//令P指向第一个节点
    while(p != NULL)//循环打印链表的数据
    {
        printf("%d ",p -> data);
        p = p -> next;
    }

    
    

    return 0;
}